- frmCustomerProfileEntry.cs
- project /
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using System.Data.SqlClient;
10 using System.Security.Cryptography;
11 namespace WarehouseManagementSystem
12 {
13 public partial class frmCustomerProfileEntry : Form
14 {
15 SqlDataReader rdr = null;
16 SqlConnection con = null;
17 SqlCommand cmd = null;
18 ConnectionString cs = new ConnectionString();
19 public frmCustomerProfileEntry()
20 {
21 InitializeComponent();
22 }
23
24 private void btnSave_Click(object sender, EventArgs e)
25 {
26 if (txtCustomerName.Text == "")
27 {
28 MessageBox.Show("Please enter name", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
29 txtCustomerName.Focus();
30 return;
31 }
32
33 if (txtAddress.Text == "")
34 {
35 MessageBox.Show("Please enter address", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
36 txtAddress.Focus();
37 return;
38 }
39 if (txtCity.Text == "")
40 {
41 MessageBox.Show("Please enter city", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
42 txtCity.Focus();
43 return;
44 }
45
46 if (txtContactNo.Text == "")
47 {
48 MessageBox.Show("Please enter contact no.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
49 txtContactNo.Focus();
50 return;
51 }
52
53 try
54 {
55 con = new SqlConnection(cs.DBConn);
56 con.Open();
57 string ct1 = "select CustomerID from Customer where CustomerID='" + txtCustomerID.Text + "'";
58
59 cmd = new SqlCommand(ct1);
60 cmd.Connection = con;
61 rdr = cmd.ExecuteReader();
62
63 if (rdr.Read())
64 {
65 MessageBox.Show("Profile already saved", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
66
67 if ((rdr != null))
68 {
69 rdr.Close();
70 }
71 return;
72 }
73 con = new SqlConnection(cs.DBConn);
74 con.Open();
75
76 string cb = "insert into Customer(CustomerID,Customername,address,City,ContactNo,ContactNo1,Email) VALUES (@d1,@d2,@d3,@d4,@d5,@d6,@d7)";
77
78 cmd = new SqlCommand(cb);
79
80 cmd.Connection = con;
81 cmd.Parameters.AddWithValue("@d1", txtCustomerID.Text);
82 cmd.Parameters.AddWithValue("@d2", txtCustomerName.Text);
83 cmd.Parameters.AddWithValue("@d3", txtAddress.Text);
84 cmd.Parameters.AddWithValue("@d4", txtCity.Text);
85 cmd.Parameters.AddWithValue("@d5", txtContactNo.Text);
86 cmd.Parameters.AddWithValue("@d6", txtContactNo1.Text);
87 cmd.Parameters.AddWithValue("@d7", txtEmail.Text);
88
89
90 cmd.ExecuteReader();
91 MessageBox.Show("Successfully saved", "Customer Details", MessageBoxButtons.OK, MessageBoxIcon.Information);
92 btnSave.Enabled = false;
93 if (con.State == ConnectionState.Open)
94 {
95 con.Close();
96 }
97
98 con.Close();
99
100 }
101 catch (Exception ex)
102 {
103 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
104 }
105 }
106
107 private void txtContactNo_KeyPress(object sender, KeyPressEventArgs e)
108 {
109 if (char.IsDigit(e.KeyChar) || char.IsControl(e.KeyChar))
110 {
111 e.Handled = false;
112 }
113 else
114 {
115 e.Handled = true;
116 }
117 }
118
119 private void txtContactNo1_KeyPress(object sender, KeyPressEventArgs e)
120 {
121 if (char.IsDigit(e.KeyChar) || char.IsControl(e.KeyChar))
122 {
123 e.Handled = false;
124 }
125 else
126 {
127 e.Handled = true;
128 }
129 }
130
131 }
132 }